//显示大额金额（每三位数加逗号分隔）
function DisplayNumber(number) {
  return number.toString().split("")
    .reverse()
    .join("")
    .replace(/(\d{3})/g, "$1,")
    .replace(/\,$/, "")
    .split("")
    .reverse()
    .join("");
}
//数据转化
function formatNumber(n) {
  n = n.toString();
  return n[1] ? n : "0" + n;
}

// 根据时间戳转换时间
function formatTime(number, format) {
  var formateArr = ["Y", "M", "D", "h", "m", "s"];
  var returnArr = [];

  var date = new Date(number);
  returnArr.push(date.getFullYear());
  returnArr.push(formatNumber(date.getMonth() + 1));
  returnArr.push(formatNumber(date.getDate()));

  returnArr.push(formatNumber(date.getHours()));
  returnArr.push(formatNumber(date.getMinutes()));
  returnArr.push(formatNumber(date.getSeconds()));

  for (var i in returnArr) {
    format = format.replace(formateArr[i], returnArr[i]);
  }
  return format;
}
// 获取某月日期
function haveMonthDate(year, month) {
  let monthMsg = {
    startTime: year + '-' + month + '-' + '01' + ' 00:00:00',
    endTime: year + '-' + month + '-' + new Date(year, month, 0).getDate() + ' 23:59:59',
  }
  return monthMsg
}


// 筛选即将到期报道
function hasMaturity(date) {
  let policyTime = new Date(date).getTime()
  let nowTime = new Date().getTime()
  return policyTime - nowTime
}
// 获取当前日期时间(年月日)
function haveData(time) {
  var time = new Date(time);
  return time.getFullYear() +
    "." +
    (time.getMonth() + 1 < 10 ?
      "0" + (time.getMonth() + 1) :
      time.getMonth() + 1) +
    "." +
    (time.getDate() < 10 ? "0" + time.getDate() : time.getDate())
}

// 删除富文本中html标签
function deleTextElement(text){
  text = text.replace(/(\n)/g, "");
	text = text.replace(/(\t)/g, "");
	text = text.replace(/(\r)/g, "");
	text = text.replace(/<\/?[^>]*>/g, "");
	text = text.replace(/\s*/g, "");
  text = text.replace(/&nbsp;/g, "")
	return text;
}
export default {
  DisplayNumber,
  formatTime,
  haveMonthDate,
  hasMaturity,
  haveData,
  deleTextElement
}
